/*******************************************************************************
 * Copyright (c) 2006 CEA List.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     CEA List - initial API and implementation
 *******************************************************************************/
package com.cea.papyrus.diagram.classdiagram.figures;

import org.eclipse.swt.graphics.Color;

import com.cea.papyrus.core.figures.StickyNoteFigure;

/**
 * This class is used to represent the Constraint figure.
 */
public class ConstraintFigure extends StickyNoteFigure {
	
	/**
	 * Default constructor, that removes the name label from super figure
	 */
	public ConstraintFigure() {
		super();
		remove(nameLabel);
	}
	
	/**
	 * Set the body of the constraint in the figure.
	 * @param constraint the body of the constraint
	 */
	public void setConstraint(String constraint) {
		setText(constraint);
	}
	
	/* (non-Javadoc)
	 * @see com.cea.papyrus.core.common.figures.NodeFigure#setBorderColor(org.eclipse.swt.graphics.Color)
	 */
	@Override
	public void setBorderColor(Color borderColor) {
		// redefinition not to see a border around the comment
		this.borderColor = borderColor;
	}
}

	
	















//package com.cea.papyrus.core.classdiagram.figures;
//
//import org.eclipse.draw2d.Figure;
//import org.eclipse.draw2d.Graphics;
//import org.eclipse.draw2d.Label;
//import org.eclipse.draw2d.PositionConstants;
//import org.eclipse.draw2d.ToolbarLayout;
//import org.eclipse.draw2d.geometry.PointList;
//import org.eclipse.draw2d.geometry.Rectangle;
//import org.eclipse.swt.graphics.Color;
//
//import com.cea.papyrus.core.common.figures.NodeFigure;
//
///**
// * This class is used to represent the Constraint figure
// * @author Patrick Tessier
// * @since 14 sept. 06 
// */
//public class ConstraintFigure extends NodeFigure {
//
//	/** Size of the corner for the constraint figure */
//	private static final int CORNER_SIZE = 10;
//	
//	/** figure for the content of the constraint */
//	protected ConstraintContentFigure contentFigure;	
//	
//	/**
//	 * this is the inner class of Constraint figure
//	 * that contains the content of the constraint
//	 * @author Patrick Tessier
//	 * @since 14 sept. 06 
//	 */
//	class ConstraintContentFigure extends Figure {
//		protected Rectangle myBounds;
//		
//		/**
//		 * Defualt constructor
//		 */
//		public ConstraintContentFigure() {
//			ToolbarLayout layout = new ToolbarLayout();
//			
//			this.setLayoutManager(layout);
//			layout.setSpacing(0);
//			this.setOpaque(false);
//			this.setBackgroundColor(this.getBackgroundColor());
//			
//		}	
//		
//		/**
//		 * setBound is called to resize or move graphical Element by Eclipse
//		 * In the case of this package we have to call setDimension Before.
//		 * @param rect coordinate of the contentConstraint.
//		 * @see setDimension
//		 */
//		@Override
//		public void setBounds(Rectangle rect) {
//			
//			// calculate header width
//			int stereoWidth    = 0;
//			int qualifiedWidth = 0;
//			int headerHeight   = 20;
//			
//			int nameWidth = ConstraintFigure.this.getNameLabel().getPreferredSize().width;
//			headerHeight  = ConstraintFigure.this.getNameLabel().getPreferredSize().height;
//			
//
//			if (ConstraintFigure.this.getIconLabel() != null) {
//				headerHeight = headerHeight+ConstraintFigure.this.getIconLabel().getPreferredSize().height;
//			}
//			
//			//if stereotype label exist
//			if (ConstraintFigure.this.getStereotypesLabel() != null){
//				stereoWidth= ConstraintFigure.this.getStereotypesLabel().getPreferredSize().width + 4;
//				if (stereoWidth > nameWidth) {//stereotytpeLabel is greater than nameLabel
//					nameWidth = stereoWidth;
//				}
//				
//				headerHeight = headerHeight + ConstraintFigure.this.getStereotypesLabel().getPreferredSize().height;
//			}
//			if (ConstraintFigure.this.getQualifiedNameLabel() != null) {
//				qualifiedWidth = ConstraintFigure.this.getQualifiedNameLabel().getPreferredSize().width;
//				if (qualifiedWidth > nameWidth) {//qualifiedLabel is greater than nameLabel
//					nameWidth = qualifiedWidth;
//				}
//				headerHeight = headerHeight + ConstraintFigure.this.getQualifiedNameLabel().getPreferredSize().height;
//			}		
//			
//			rect = Rectangle.SINGLETON;
//			rect.setLocation(5, 5);
//			rect.setSize(nameWidth+10,headerHeight+10);
//			
//			super.setBounds(rect);
//		}
//		
//		/**
//		 * set the size of this figure.
//		 * @param rect set the dimension of the figure
//		 */
//		public void setDimension(Rectangle rect){		
//			this.myBounds = rect;
//		}
//	}
//
//	/**
//	 * used to create the constraint figure
//	 * a rectangle with a corner
//	 */
//	public ConstraintFigure() {
//		ToolbarLayout layout = new ToolbarLayout();
//		layout.setMinorAlignment(ToolbarLayout.ALIGN_TOPLEFT);
//		this.setLayoutManager(layout);
//		
//		
//		this.contentFigure = new ConstraintContentFigure();
//		this.add(this.contentFigure);
//		
//		// these lines are used to place the constraint body at left
//		this.getConstraintLabel().setTextPlacement(PositionConstants.LEFT);
//		this.getConstraintLabel().setTextAlignment(PositionConstants.LEFT);
//		
//		
//	}
//	
//	/**
//	 * used to display the content of the constraint
//	 * @param constraintliteral
//	 */
//	public void setConstraint(String constraintliteral){
//		this.getConstraintLabel().setText("{ "+constraintliteral+"}");  //$NON-NLS-1$//$NON-NLS-2$
//	}
//	
//	/**
//	 * to obtain the label that contains the content of the figure
//	 * @return the label that contains the content of the figure
//	 */
//	public Label getConstraintLabel(){
//		return this.getNameLabel();
//	}
//
//	/**
//	 * setBound is called to resize or move graphical Element by Eclipse
//	 * It call setBound of each subFigure.
//	 * In the case of contentPackage we call setDimension
//	 * 
//	 * @see setDimension
//	 * @param rect coordinate of the contentPackage.
//	 */
//	@Override
//	public void setBounds(Rectangle rect) {
//		super.setBounds(rect);
//
//		//header
//		this.contentFigure.setBounds(rect);	
//	}
//		
//	/** to obtain the content of the figure
//	 * @return IFigure the cotnetn of the figure
//	 */
//	public ConstraintContentFigure getContent() {
//		return this.contentFigure;
//	}
//	
//	/*
//	 * (non-Javadoc)
//	 * @see org.eclipse.draw2d.Figure#paint(org.eclipse.draw2d.Graphics)
//	 */
//	@Override
//	public void paint (Graphics graphics) {     
//		
//		Rectangle rect=this.getBounds().getCopy();
//		
//		// Prepare points
//		final int orig_x = rect.x;
//		final int orig_y = rect.y;
//		final int width  = rect.width;
//		final int height = rect.height;
//		final int left   = orig_x;
//		final int top    = orig_y;
//		final int right  = orig_x + width  - 1;
//		final int bottom = orig_y + height - 1;
//
//		// Drawing main polygon
//		PointList plist = new PointList();
//		// left up corner
//		plist.addPoint(left, top);
//		// right top corner
//		plist.addPoint(right - ConstraintFigure.CORNER_SIZE, top);
//		plist.addPoint( right - ConstraintFigure.CORNER_SIZE, top + ConstraintFigure.CORNER_SIZE);
//		plist.addPoint(right, top + ConstraintFigure.CORNER_SIZE);
//		// right bottom corner
//		plist.addPoint(right, bottom);
//		// left bottom corner
//		plist.addPoint(left, bottom);
//
//		graphics.setBackgroundColor(this.getBackgroundColor());
//		graphics.fillPolygon(plist);
//		graphics.drawPolygon(plist);
//
//		// Drawing corner
//		plist = new PointList();
//		plist.addPoint(right - ConstraintFigure.CORNER_SIZE, top);
//		plist.addPoint(right, top + ConstraintFigure.CORNER_SIZE);
//		plist.addPoint(right - ConstraintFigure.CORNER_SIZE, top + ConstraintFigure.CORNER_SIZE);
//		graphics.setBackgroundColor(this.getBackgroundColor());
//		graphics.fillPolygon(plist);
//		graphics.drawPolygon(plist);
//
//		// Small trick to avoid having the icon twice
//		// one time during super.paint() and the other one just after
//		if (this.getIconLabel() != null) {
//			// place some space on the right so that the icon
//			// will be place left to the corner
//			this.getIconLabel().setText("\0"); //$NON-NLS-1$
//			this.getIconLabel().setIconTextGap(ConstraintFigure.CORNER_SIZE);
//			this.getIconLabel().setTextPlacement(PositionConstants.EAST);
//		}
//		
//		super.paint (graphics);
//		/////////////////////////////////////////////////////////////
//	}
//
//	/* (non-Javadoc)
//	 * @see org.eclipse.draw2d.Figure#useLocalCoordinates()
//	 */
//	@Override
//	protected boolean useLocalCoordinates() {
//		return true;
//	}
//	
//	/**
//	 * to obtain the width of the content figure
//	 * @return the width of the content figure
//	 */
//	public int getHeadWitdh()  {
//		return this.contentFigure.getPreferredSize().width;
//	}
//	
//	/**
//	 * to obtain the height of the content figure
//	 * @return the height of the content figure
//	 */
//	public int getHeadHeight() { 
//		return this.contentFigure.getPreferredSize().height;
//	}
//	
//	/* (non-Javadoc)
//	 * @see com.cea.papyrus.core.common.figures.NodeFigure#setBorderColor(org.eclipse.swt.graphics.Color)
//	 */
//	@Override
//	public void setBorderColor(Color borderColor) {
//		// redefinition not to see a border around the constraint
//		this.borderColor = borderColor;
//	}
//}
//
//	
//	
//	
//	
//
//
//
//
//
//
//
//
//
//
//
//
//
////package com.cea.papyrus.core.classdiagram.figures;
////
////import org.eclipse.draw2d.Figure;
////import org.eclipse.draw2d.Graphics;
////import org.eclipse.draw2d.Label;
////import org.eclipse.draw2d.PositionConstants;
////import org.eclipse.draw2d.ToolbarLayout;
////import org.eclipse.draw2d.geometry.PointList;
////import org.eclipse.draw2d.geometry.Rectangle;
////import org.eclipse.swt.graphics.Color;
////
////import com.cea.papyrus.core.common.figures.NodeFigure;
////
////
////
/////**
//// * This is the class that represents the figure of a constraint.
//// */
////public class ConstraintFigure extends NodeFigure {
////
////	/** The content figure. */
////	protected ConstraintContentFigure contentFigure;
////
////	/** The Constant CORNER_SIZE. */
////	private static final int CORNER_SIZE = 10;
////	
////	/** The body of the constraint */
////	private String body="";
////	private String name="";
////
////	/** The content label. */
////	private Label contentLabel;
////
////	/**
////	 * The Class ConstraintContentFigure.
////	 */
////	class ConstraintContentFigure extends Figure {
////		
////		/** The bounds of the ConstraintConstentFigure */
////		protected Rectangle contentBounds;
////
////		/**
////		 * The Constructor of the constraintContentFigure
////		 */
////		public ConstraintContentFigure() {
////
////			final ToolbarLayout layout = new ToolbarLayout();
////			layout.setVertical(false);
////			this.setLayoutManager(layout);
////			layout.setSpacing(2);
////			this.setOpaque(false); // non-transparent figure
////			this.setBackgroundColor(this.getBackgroundColor());
////			// these lines are used to place the constraint body at left
////			ConstraintFigure.this.getNameLabel().setTextPlacement(PositionConstants.LEFT);
////			ConstraintFigure.this.getNameLabel().setTextAlignment(PositionConstants.LEFT);
////		}	
////
////		/**
////		 * setBound is called to resize or move graphical Element by Eclipse
////		 * In the case of this package we have to call setDimension Before.
////		 * 
////		 * @param rect coordinate of the contentPackage.
////		 * 
////		 * @see setDimension
////		 */
////		@Override
////		public void setBounds(Rectangle rect) {
////
////			// calculate header width
////			int stereoWidth    = 0;
////			int qualifiedWidth = 0;
////			int contentWidth   = 0;
////			int headerHeight   = 20;
////
////			int nameWidth = ConstraintFigure.this.getNameLabel().getPreferredSize().width;
////			headerHeight  = ConstraintFigure.this.getNameLabel().getPreferredSize().height;
////
////			if (ConstraintFigure.this.getIconLabel() != null) {
////				headerHeight = headerHeight+ConstraintFigure.this.getIconLabel().getPreferredSize().height;
////			}
////
////			// if stereotype label exist
////			if (ConstraintFigure.this.getStereotypesLabel() != null) {
////				stereoWidth = ConstraintFigure.this.getStereotypesLabel().getPreferredSize().width + 4;
////				if(stereoWidth > nameWidth) {//stereotytpeLabel is greater than nameLabel
////					nameWidth = stereoWidth;
////				}
////
////				headerHeight = headerHeight+ConstraintFigure.this.getStereotypesLabel().getPreferredSize().height;
////			}
////
////			if (ConstraintFigure.this.getQualifiedNameLabel() != null) {
////				qualifiedWidth = ConstraintFigure.this.getQualifiedNameLabel().getPreferredSize().width;
////				if(qualifiedWidth > nameWidth) {//qualifiedLabel is greater than nameLabel
////					nameWidth = qualifiedWidth;
////				}
////				headerHeight = headerHeight+ConstraintFigure.this.getQualifiedNameLabel().getPreferredSize().height;
////			}
////
////			if (ConstraintFigure.this.contentLabel != null) {
////				contentWidth = ConstraintFigure.this.contentLabel.getPreferredSize().width;
////				if(contentWidth > nameWidth) {//contentLabel is greater than nameLabel
////					nameWidth = contentWidth;
////				}
////				headerHeight = headerHeight+ConstraintFigure.this.contentLabel.getPreferredSize().height;
////			}
////
////			rect = Rectangle.SINGLETON;
////			rect.setLocation(10, 5);
////			rect.setSize(nameWidth+10, headerHeight+10);
////
////			super.setBounds(rect);
////		}
////
////		/**
////		 * set the size of this figure.
////		 * 
////		 * @param rect the rect
////		 */
////		public void setDimension(final Rectangle rect) {			
////			this.contentBounds=rect;
////		}
////	}
////
////	/**
////	 * The Constructor of the constraint figure
////	 */
////	public ConstraintFigure() {
////		final ToolbarLayout layout = new ToolbarLayout();
////		this.setLayoutManager(layout);
////		layout.setSpacing(10);
////		this.contentFigure = new ConstraintContentFigure();
////		super.add(this.contentFigure);
////
////		//add Constraint body
////		this.contentLabel = new Label("");
////		this.contentLabel.setFont(this.getFont());
////		this.contentLabel.setLabelAlignment(PositionConstants.LEFT);
////		this.contentFigure.add(this.contentLabel);
////	}
////
////	/**
////	 * Sets the body.
////	 * 
////	 * @param body the body
////	 */
////	public void setBody(final String body) {
////		if (body!=""){
////			this.body=body;
////			this.contentLabel.setText(body+"}");
////		}
////		this.getNameLabel().setText(" {"+name+":");
////	}
////
////	/**
////	 * Sets the name byt taking account the grammar of constraint in UML
////	 * 
////	 * @param name the name
////	 */
////	@Override
////	public void setName( final String name )
////	{
////		this.name=name;
////		if( this.body==""){
////			this.getNameLabel().setText(" {"+name+"}");
////			this.contentLabel.setText(body);
////		}
////		else{
////			this.getNameLabel().setText(" {"+name+":");
////			this.contentLabel.setText(body+"}");
////		}
////	}
////	
////	/**
////	 * Gets the body label.
////	 * 
////	 * @return the body label
////	 */
////	public Label getBodyLabel() {
////		return this.contentLabel;
////	}
////
////	/**
////	 * setBound is called to resize or move graphical Element by Eclipse
////	 * It call setBound of each subFigure.
////	 * In the case of contentPackage we call setDimension
////	 * 
////	 * @param rect coordinate of the contentPackage.
////	 * 
////	 * @see setDimension
////	 */
////	@Override
////	public void setBounds(final Rectangle rect) {
////		super.setBounds(rect);
////
////		//header
////		this.contentFigure.setBounds(rect);	
////	}
////
////	/**
////	 * set the border coler of the figure.
////	 * 
////	 * @param borderColor the border color
////	 */
////	@Override
////	public void setBorderColor(final Color borderColor) {
////		this.borderColor = borderColor;
////	}
////
////
////	/**
////	 * to obtain the header of the package figure.
////	 * 
////	 * @return IFigure the header
////	 */
////	public ConstraintContentFigure getContent() {
////		return this.contentFigure;	
////	}
////
////	/*
////	 * (non-Javadoc)
////	 * @see org.eclipse.draw2d.Figure#paint(org.eclipse.draw2d.Graphics)
////	 */
////	/**
////	 * Paint the constraint figure
////	 * 
////	 * @param graphics the graphics
////	 */
////	@Override
////	public void paint (final Graphics graphics) {
////
////		final Rectangle rect=this.getBounds().getCopy();
////
////		// Prepare points
////		final int orig_x = rect.x;
////		final int orig_y = rect.y;
////		final int width  = rect.width;
////		final int height = rect.height;
////		final int left   = orig_x;
////		final int top    = orig_y;
////		final int right  = orig_x + width  - 1;
////		final int bottom = orig_y + height - 1;
////
////		// Drawing main polygon
////		PointList plist = new PointList();
////		plist.addPoint(
////				left
////				, top);
////		plist.addPoint(
////				right - ConstraintFigure.CORNER_SIZE
////				, top);
////		plist.addPoint(
////				right - ConstraintFigure.CORNER_SIZE
////				, top + ConstraintFigure.CORNER_SIZE);
////		plist.addPoint(
////				right
////				, top + ConstraintFigure.CORNER_SIZE);
////		plist.addPoint(
////				right
////				, bottom);
////		plist.addPoint(
////				left
////				, bottom);
////
////		graphics.setBackgroundColor(this.getBackgroundColor());
////		graphics.fillPolygon(plist);
////		graphics.drawPolygon(plist);
////
////		// Drawing corner
////		plist = new PointList();
////		plist.addPoint(
////				right - ConstraintFigure.CORNER_SIZE
////				, top);
////		plist.addPoint(
////				right
////				, top + ConstraintFigure.CORNER_SIZE);
////		plist.addPoint(
////				right - ConstraintFigure.CORNER_SIZE
////				, top + ConstraintFigure.CORNER_SIZE);
////		graphics.setBackgroundColor(this.getBackgroundColor());
////		graphics.fillPolygon(plist);
////		graphics.drawPolygon(plist);
////
////		// Small trick to avoid having the icon twice
////		// one time during super.paint() and the other one just after
////		if (this.getIconLabel() != null) {
////			// place some space on the right so that the icon
////			// will be place left to the corner
////			this.getIconLabel().setText("\0");
////			this.getIconLabel().setIconTextGap(ConstraintFigure.CORNER_SIZE);
////			this.getIconLabel().setTextPlacement(PositionConstants.EAST);
////		}
////		super.paint (graphics);
////		/////////////////////////////////////////////////////////////
////	}
////
////	/**
////	 * Use local coordinates.
////	 * 
////	 * @return true, if use local coordinates
////	 */
////	@Override
////	protected boolean useLocalCoordinates() {return true;}
////
////	/**
////	 * Gets the head witdh.
////	 * 
////	 * @return the head witdh
////	 */
////	public int getHeadWitdh()  { return this.contentFigure.getPreferredSize().width;}
////	
////	/**
////	 * Gets the head height.
////	 * 
////	 * @return the head height
////	 */
////	public int getHeadHeight() { return this.contentFigure.getPreferredSize().height;}
////}
